/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.just.dusin.ooii.util;

/**
 *
 * @author Administrator
 */
public class NumberUtil {
    private static final int fractionalDigit=2;//保留小数位数
    public static double fixed(double value,int fac){
        int mutil=1;
        for(int i=0;i<fac;i++)
            mutil*=10;
        int intValue=(int)(value*mutil+0.5);
        value = (double)intValue/mutil;
        return value;
    }
    
    public static double fixed(double value){
        return fixed(value,fractionalDigit);
    }
    
    public static byte[] toByteArray(short a){
        byte[] r = new byte[2];
        r[1] = (byte)a;
        r[0] = (byte)(a>>8);
        return r;
    }
    
    public static byte[] toByteArray(int a){
        byte[] r = new byte[4];
        r[3] = (byte)a;
        r[2] = (byte)(a>>8);
        r[1] = (byte)(a>>16);
        r[0] = (byte)(a>>24);
        return r;
    }
    
    
    public static byte toBCD(byte a){
        byte l;
        byte h;
        byte r;
        l = (byte)(a%10);
        h = (byte)(a/10);
        r =(byte)( (h<<4)|l);
        return r;
    }    
}
